package com.yangquan.ayuan.threadTermination;

import java.util.concurrent.TimeUnit;

public class InterruptExample extends Thread {
    @Override
    public void run() {
        int i = 0;
        while (!Thread.currentThread().isInterrupted()) {
            i++;
        }
        System.out.println("线程被中断 - " + i);
    }
}

class App_5 {
    public static void main(String[] args) throws InterruptedException {
        InterruptExample example = new InterruptExample();
        example.start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println("before:InterruptExample 中断标记: " + example.isInterrupted());
        example.interrupt();
        System.out.println("after:InterruptExample 中断标记: " + example.isInterrupted());
    }
}